const backstage = {
    namespaced: true,
    state: {
        backstageData: [], //后台等级树形节点
        backstageList: [],
        eigenvalueTags: [],
        sensorTreeData: [], //传感器树形节点
        deviceType: [],
        sensorType: [],
        cycleList: [],
        roleList: [],
        menuList: [],
        menuType: [],
        mqttConfig: {},
        domainTags: [],
        waveTags: [],
        wavcacq: [],
        sys_eig: [],
        sys_wave: [],
        algorithmData: [],
    },
    getters: {
        getMenu(state) {
            return state.menuType
        },
    },
    mutations: {
        // 获取特征值类型
        eigenvalueGetlist(state, a) {
            state.eigenvalueTags = a
        },
        getEigtag(state, a) {
            state.sys_eig = a
        },
        getWavetag(state, a) {
            state.sys_wave = a
        },
        domainTagsGetlist(state, a) {
            state.domainTags = a
        },
        waveTagsGetlist(state, a) {
            state.waveTags = a
        },
        // 存储后台节点的树形结构
        getBackstage(state, value) {
            function removeChildren(arr) {
                arr.forEach((e) => {
                    if (e.children.length == 0) e.children = undefined
                    else removeChildren(e.children)
                })
            }
            removeChildren(value)
            state.backstageData = value
        },
        getAlgorithmData(state, value) {
            state.algorithmData = value
        },
        getSensorTreeData(state, value) {
            state.sensorTreeData = value
        },
        // 设置传感器树形结构节点
        setSensorTreeData(state, data) {
            let { userLevel } = data
            if (userLevel == 4)
                state.sensorTreeData.forEach((group) => {
                    group.children.forEach((company) => {
                        company.children.forEach((factory) => {
                            factory.children.forEach((zone) => {
                                if (zone.value == data.id) {
                                    zone.children = data.tree
                                }
                            })
                        })
                    })
                })
            else if (userLevel == 3)
                state.sensorTreeData.forEach((company) => {
                    company.children.forEach((factory) => {
                        factory.children.forEach((zone) => {
                            if (zone.value == data.id) {
                                zone.children = data.tree
                            }
                        })
                    })
                })
            else if (userLevel == 2)
                state.sensorTreeData.forEach((factory) => {
                    factory.children.forEach((zone) => {
                        if (zone.value == data.id) {
                            zone.children = data.tree
                        }
                    })
                })
            else if (userLevel == 1)
                state.sensorTreeData.forEach((zone) => {
                    if (zone.value == data.id) {
                        zone.children = data.tree
                    }
                })
        },
        // 存储设备类型
        getDeviceType(state, value) {
            state.deviceType = value
        },
        // 获取测点类型
        getSensorType(state, value) {
            state.sensorType = value
        },
        //点检频率
        getCycleList(state, value) {
            state.cycleList = value
        },
        getWavcacq(state, value) {
            state.wavcacq = value
        },
        getRoleList(state, value) {
            state.roleList = value
        },
        getBackstageList(state, value) {
            state.backstageList = value
        },
        getMenuList(state, value) {
            state.menuList = value
        },
        getMenuType(state, value) {
            state.menuType = value
        },
        getMqttConfig(state, value) {
            state.mqttConfig = value
        },
    },
}

export default backstage
